import api from './api'

// 支付相关API
const payAPI = {
  // 创建支付宝支付
  createAlipay(orderId, data = {}) {
    return api.post('/pay/alipay/create', {
      orderId,
      returnUrl: data.returnUrl || window.location.origin + '/payment/result',
      notifyUrl: data.notifyUrl || '/api/pay/alipay/notify',
      ...data
    })
  },
  
  // 查询支付宝支付结果
  queryAlipay(orderId) {
    return api.get(`/pay/alipay/query/${orderId}`)
  },
  
  // 创建微信支付
  createWechatPay(orderId, data = {}) {
    return api.post('/pay/wechat/create', {
      orderId,
      type: data.type || 'JSAPI', // JSAPI, NATIVE, APP, MWEB
      returnUrl: data.returnUrl || window.location.origin + '/payment/result',
      notifyUrl: data.notifyUrl || '/api/pay/wechat/notify',
      ...data
    })
  },
  
  // 查询微信支付结果
  queryWechatPay(orderId) {
    return api.get(`/pay/wechat/query/${orderId}`)
  },
  
  // 创建银行卡支付
  createBankPay(orderId, data = {}) {
    return api.post('/pay/bank/create', {
      orderId,
      bankCode: data.bankCode,
      cardType: data.cardType || 'DEBIT', // DEBIT, CREDIT
      returnUrl: data.returnUrl || window.location.origin + '/payment/result',
      notifyUrl: data.notifyUrl || '/api/pay/bank/notify',
      ...data
    })
  },
  
  // 查询银行卡支付结果
  queryBankPay(orderId) {
    return api.get(`/pay/bank/query/${orderId}`)
  },
  
  // 统一创建支付
  createPayment(orderId, paymentMethod, data = {}) {
    return api.post('/pay/create', {
      orderId,
      paymentMethod, // alipay, wechat, bank
      ...data
    })
  },
  
  // 统一查询支付结果
  queryPayment(orderId) {
    return api.get(`/pay/query/${orderId}`)
  },
  
  // 获取支付方式列表
  getPaymentMethods() {
    return api.get('/pay/methods')
  },
  
  // 支付回调处理（前端回调）
  handlePaymentCallback(data) {
    return api.post('/pay/callback', data)
  },
  
  // 获取支付渠道配置
  getPaymentConfigs() {
    return api.get('/pay/configs')
  }
}

export default payAPI